package com.zxlspace.proxy;

/**
 * 静态代理 设计模式
 * 1.真实角色
 * 2.代理角色：持有真实角色的引用
 * 3.二者实现相同的接口
 */
public class StaticProxy {

    public static void main(String[] args) {
        Marry you = new You();
        WeddingCompany weddingCompany = new WeddingCompany(you);
        weddingCompany.marry();
    }

}

    //接口
    interface Marry{
       public abstract void marry();
    }

    //真实角色
    class You implements Marry{
        @Override
        public void marry() {
            System.out.println("you and 嫦娥结婚了....");
        }
    }

    class WeddingCompany implements Marry{
        private Marry you;

        public WeddingCompany() {

        }

        public WeddingCompany(Marry you) {
            this.you = you;
        }

        private void before() {
            System.out.println("布置猪窝");
        }

        private void after() {
            System.out.println("闹玉兔");
        }

        @Override
        public void marry() {
            before();
            you.marry();
            after();
        }
    }

